import api from './index'

// 获取轮播图
export const getBanners = (name) => {
  return api.get(`banner/name/${name}`)
}

// 获取分类网格
export const getCategoryGrid = () => {
  return api.get('category/grid/all')
}

// 获取主题
export const getThemes = (names) => {
  return api.get('theme/by/names', {
    params: { names }
  })
}

// 获取主题商品
export const getThemeSpu = (name) => {
  return api.get(`theme/name/${name}/with_spu`)
}

// 获取最新商品
export const getLatestSpu = (start = 0, count = 10) => {
  return api.get('spu/latest', {
    params: { start, count }
  })
}

// 获取商品列表
export const getSpuList = (params = {}) => {
  return api.get('spu/latest', {
    params: {
      start: params.page ? (params.page - 1) * (params.pageSize || 10) : 0,
      count: params.pageSize || 10,
      ...params
    }
  })
}

// 获取商品详情
export const getSpuDetail = (id) => {
  return api.get(`spu/id/${id}/detail`)
}

// 获取商品简化信息
export const getSpuSimplify = (id) => {
  return api.get(`spu/id/${id}/simplify`)
}

// 获取活动
export const getActivity = () => {
  return api.get('activity/list')
}

// 根据分类获取商品列表
export const getSpuByCategory = (cid, isRoot = false, start = 0, count = 10) => {
  return api.get(`spu/by/category/${cid}?is_root=${isRoot}&start=${start}&count=${count}`)
} 